﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        //1、生成一个随机整型数组，长度是10，内容是1~10，数组内容不重复。
        static void Main(string[] args)
        {
            int[] arr = new int[10];
            Random random = new Random();

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = random.Next(1, 11);
                if (i > 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (arr[i] == arr[j])
                        {
                            i--;
                        }
                    }
                }
            }
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " ");
            }
            Console.WriteLine("\n");

            //2、生成0-5之间的随机小数，保留两位小数。
            Random random1 = new Random();
            for (int i = 0; i < 2; i++)
            {
                Console.Write(random1.Next(0,5));
                Console.WriteLine(random1.NextDouble().ToString("#.00"));
            }
            Console.WriteLine("\n");

            //3、生成4 - 7之间的随机小数，保留两位小数。
            Random random2 = new Random();
            for (int i = 0; i < 2; i++)
            {
                Console.Write(random2.Next(4,7));
                Console.WriteLine(random2.NextDouble().ToString("#.00"));//("#.00")意思是保留两位小数
            }
            Console.WriteLine("\n");

            //4、用户输入邮箱，请验证其合法性。
            
            while (true)
            {
                Console.WriteLine("请输入邮箱：");
                string str = Console.ReadLine();
                //tongwenyun196  @ 163 .  com
                if (Regex.IsMatch(str,@"^(\w)*@+(\w)+(\.\w)+(\w)+$"))
                {
                    Console.WriteLine("正确");
                    break;
                }
                else
                {
                    Console.WriteLine("错误");
                }
            }
            Console.WriteLine("\n");
            //5、用户输入手机号码，请验证其合法性。
            while (true)
            {
                Console.WriteLine("请输入手机号码：");
                string str = Console.ReadLine();

                if (Regex.IsMatch(str,@"\d\d\d\d\d\d\d$"))
                {
                    Console.WriteLine("正确");
                    break;
                }
                else
                {
                    Console.WriteLine("错误");
                }
            }

        }
    }
}
